package com.ziyia.a4_5_6;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.StackView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private StackView stackView;

    private int[] images = {
            R.drawable.img,
            R.drawable.img_1,
            R.drawable.img_2,
            R.drawable.img_3,
            R.drawable.img_4,
            R.drawable.img_5
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        stackView = findViewById(R.id.stack);

        List<Map<String, Object>> maps = new ArrayList<>();
        for (int i = 0; i < images.length; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("image", images[i]);
            maps.add(map);
        }
        SimpleAdapter adapter = new SimpleAdapter(this, maps, R.layout.image, new String[]{"image"}, new int[]{R.id.image});
        stackView.setAdapter(adapter);
    }

    public void next(View view) {
        stackView.showNext();
    }

    public void prev(View view) {
        stackView.showPrevious();
    }
}
